/*
 *
 * 名称：二十四节
 * 功能：24小时或24节气的计算功能
 * 作者：清河张
 * 时间：2025.05.11
 *
 */

#include "jie24.h"
#include "xzqm.h"


JIE24::JIE24(int zhoujie, int yu)
{
    _zhoujie = zhoujie;
    _yu = yu;
}

void JIE24::zhoujie(int zhoujie)
{
    _zhoujie = zhoujie;
}

void JIE24::zhou(int z)
{
    _zhoujie = _zhoujie % 24 + z * 24;
}

void JIE24::jie(int j)
{
    _zhoujie = _zhoujie / 24 * 24 + j;
    _yu = 0;
}

void JIE24::yuclear()
{
    _yu = 0;
}

bool JIE24::operator ==(int n) const
{
    return (!invalid() ) && n == _zhoujie % 24;
}

JIE24 JIE24::operator +(int n) const
{
    JIE24 jq = *this;
    jq._zhoujie += n;
    return jq;
}

JIE24 JIE24::operator -(int n) const
{
    return operator +(- n);
}

JIE24& JIE24::operator +=(int n)
{
    _zhoujie += n;
    return *this;
}

JIE24& JIE24::operator -=(int n)
{
    _zhoujie -= n;
    return *this;
}

int JIE24::zhoujie() const
{
    return _zhoujie;
}

int JIE24::zhou() const
{
    return _zhoujie / 24;
}

int JIE24::jie() const
{
    return _zhoujie % 24;
}

int JIE24::yu() const
{
    return _yu;
}

bool JIE24::invalid() const
{
    return _zhoujie < 0;
}

bool JIE24::yinyang() const
{
    return _zhoujie % 24 < 12;
}

bool JIE24::jiao() const
{
    return _zhoujie % 24 == 0;
}

int JIE24::zhi12() const
{
    return invalid() ? -1 : ( XUNHUAN ( _zhoujie + 1, 24 ) / 2 ) % 12;
}

int JIE24::yufen(int n) const
{
    return invalid() ? -1 : _yu / n;
}

int JIE24::xiaowei(int n) const
{
    return invalid() ? -1 : _yu % n;
}

int JIE24::jiejuli(int zhoujie) const
{
    if(invalid()) return -1;
    return _zhoujie - zhoujie;
}

int JIE24::jiejuliz(int zhoujie, int z) const
{
    return XUNHUAN ( jiejuli(zhoujie), z );
}

int JIE24::jiejuliz(int zhou, int jie, int z) const
{
    return XUNHUAN ( jiejuli(zhou*24 + jie), z );
}

void JIE24::zhoucha(int zx, int &zhou, int &order) const
{
    if(invalid()) return;
    zhou = ( _zhoujie + zx ) / 24;
    order = XUNHUAN ( _zhoujie + zx, 24 );
}

void JIE24::zhouchax(int zx, int &zhou, int &order) const
{
    zhoucha(zx,zhou,order);
    if(!order)
    {
        order = 24;
        zhou -= 1;
    }
}

JIE24 JIE24::xiangqian(int jie, int yu) const
{
    if(invalid())
        return -1;

    int jiex, jie0;
    jie = jie % 24;//需要的节
    jiex = jie - _zhoujie % 24;//节差

    jie0 = jiex <= 0 ? _zhoujie + jiex : _zhoujie + jiex - 24;

    return JIE24(jie0, yu);
}

JIE24 JIE24::xianghou(int jie, int yu) const
{
    int jiex, jie0;

    if(invalid())
        return -1;

    jie = jie % 24;//需要的节
    jiex = _zhoujie % 24 - jie;//节差

    jie0 = jiex <= 0 ? _zhoujie - jiex : _zhoujie - jiex + 24;

    return JIE24(jie0, yu);
}



